package code.D1214;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * author : yeswater
 * date : 2023/12/14
 * 
 * 只出现一次的数字
 * 
 */

public class T136 {
    // set
    public int singleNumber(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (!set.contains(num)) {
                set.add(num);
            } else {
                set.remove(num);
            }
        }
        return new ArrayList<Integer>(set).get(0);
    }
    
    // 异或
    public int singleNumber1(int[] nums) {
        int ans = 0;
        for (int num : nums) {
            ans ^= num;
        }
        return ans;
    }
}
